package com.anlzou.controller;

import com.anlzou.commons.ApachePOIUtils;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@EnableAutoConfiguration
@Controller
public class TestController {

    @RequestMapping("/test1")
    @ResponseBody
    public String apachePOITest(){
        ApachePOIUtils apachePOIUtils = new ApachePOIUtils("E:/resources/template.xlsx");

        // 动态插入数据-增加行
        List<Map<String, Object>> datas = new ArrayList<>();
        for (int i = 0; i < 5; i++) {
            Map data = new HashMap<>();
            data.put("name", "name" + i);
            data.put("age", "age" + i);
            data.put("sex", "sex" + i);
            datas.add(data);
        }
        apachePOIUtils.appendRows(5, datas, new String[] { "name", "age", "sex" });
        apachePOIUtils.exportExcel(new File("E:/resources/output.xlsx"));

        return "ok";
    }
}
